﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Security.Principal;

namespace RentAWorker.WebNew
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "rent/{action}/{resourceid}",                           // URL with parameters
                new { controller = "Rent", action = "List", resourceid = 0 }  // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            //
            // Note that the web application ALWAYS acts as "FrontOffice"
            //
            // WARNING: this works only for in-process hosted components, for
            //          out-of-process hosted business components (e.g. WCF) you
            //          need to authenticate appropriately with the WCF services and
            //          the WCF services decide in which group you are in!!!
            //
            GenericPrincipal NewPrin = null;
            if (HttpContext.Current.User != null)
            {
                NewPrin = new GenericPrincipal(
                                   HttpContext.Current.User.Identity,
                                   new string[] { "FrontOffice" });
            }
            else
            {
                NewPrin = new GenericPrincipal(
                                   new GenericIdentity(string.Empty),
                                   new string[] { "FrontOffice" });
            }
            HttpContext.Current.User = (IPrincipal)NewPrin;
        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}